package com.liangzong.betspider.service;

import com.liangzong.betspider.entity.TeamPoint;
import com.liangzong.betspider.mapper.TeamPointMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.Assert;

import java.util.List;

@Service
public class TeamPointService {
    @Autowired
    TeamPointMapper teamPointMapper;

    @Transactional(rollbackFor = Throwable.class)
    public boolean addOrUpdate(String teamId, List<TeamPoint> homeTeamPointList, List<TeamPoint> awayTeamPointList) {
        Example o = new Example(TeamPoint.class);
        o.and().andEqualTo("teamId", teamId);
        //清理数据
        teamPointMapper.deleteByExample(o);
        //批量保存
        Assert.isTrue(teamPointMapper.insertList(homeTeamPointList) > 0, "保存主队盘口异常");
        Assert.isTrue(teamPointMapper.insertList(awayTeamPointList) > 0, "保存客队盘口异常");
        return true;
    }

    public List<TeamPoint> getByTeamId(String teamId){
        Example o = new Example(TeamPoint.class);
        o.and().andEqualTo("teamId", teamId);
        return teamPointMapper.selectByExample(o);
    }
}
